#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;

int n, m;
int a[N];

bool check() {
  int i = 1, j = 1;
  stack<int> st;
  while (j <= n) {
    if (st.empty() || st.top() != a[j]) st.push(i++);
    if (st.size() && st.top() == a[j]) st.pop(), j++;
    if (i > n + 1) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> n && n) {
    while (cin >> a[1] && a[1]) {
      rep(i, 2, n) cin >> a[i];
      if (check())
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
    cout << endl;
  }
  return 0;
}